﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WMS.Infrastructure.BaseRepository;

namespace Zocono.WCS.Infrastructure.Repository
{
    public class FunctionRepository : BaseRepository<FunctionInfo>, IFunctionRepository
    {
        public FunctionRepository(SqlSugarClient context = null) : base(context)
        {

        }
        /// <summary>
        /// 根据上级菜单ID和状态查询菜单列表
        /// </summary>
        /// <param name="pId">上级菜单ID，0=顶级单</param>
        /// <param name="status">状态1=正常</param>
        /// <returns></returns>
        public async Task<List<FunctionInfo>> GetFunctionInfoListByPidAsync(long pId, int status)
        {
            return await Context.Queryable<FunctionInfo>().Where(it => it.Pid == pId && it.Status == status).ToListAsync();
        }
        /// <summary>
        /// 修改菜单状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public async Task<bool> UpdateStatusByIdAsync(long id, int status)
        {
            var info = new FunctionInfo();
            info.ID = id;
            info.Status = status;
            var result = await Context.Updateable(info).UpdateColumns(i => new { i.Status }).WhereColumns(i => new { i.ID }).ExecuteCommandAsync();
            if (result > 0)
                return true;
            return false;
        }
    }
}
